<template>
	<view class="wrap">
		<view class="remind-text">
			请填写新的信息以完善您的帐户
		</view>

		<u-form class="form" :model="model" ref="uForm">
			<u-form-item label="昵称" prop="nickname" label-width="180">
				<u-input type="text" v-model="model.nickname" placeholder="请输入新的昵称" />
			</u-form-item>
			<u-form-item label="地址" prop="address" label-width="180">
				<u-input v-model="model.address" type="select" @click="showCity = true" />
				<u-picker mode="region" v-model="showCity" @confirm='changeCity' />
			</u-form-item>
			<u-form-item label="手机" prop="phone" label-width="180">
				<u-input type="number" v-model="model.phone" placeholder="请输入新手机号" />
			</u-form-item>
			<u-form-item label="微信" prop="weixin" label-width="180">
				<u-input type="text" v-model="model.weixin" placeholder="请输入新微信号" />
			</u-form-item>
			<u-form-item label="邮箱" prop="email" label-width="180">
				<u-input type="text" v-model="model.email" placeholder="请输入新的邮箱" />
			</u-form-item>
		</u-form>

		<view class="form-footer">
			<u-button class="btn" type="primary" @click="submit">提交</u-button>
			<u-button class="btn" type="default" @click="cancel">取消</u-button>
		</view>
	</view>
</template>
<script>
	import base64 from '@/common/base64.js';
	export default {
		data() {
			return {
				model: {
					id: 0,
					nickname: '',
					address: '',
					phone: '',
					weixin: '',
					email: ''
				},
				showCity: false,
			}
		},
		methods: {
			submit() {
				this.$u.api.user.changeInfo(this.model).then(res => {
					if (res.code == '200') {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: function() {
								uni.reLaunch({
									url: '/pages/sys/user/index'
								});
							}
						});
					} else {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
						});
					}
				});
			},
			cancel() {
				uni.navigateBack();
			},
			changeCity(cityObj) {
				this.model.address = cityObj.province.label + cityObj.city.label + cityObj.area.label;
			},
		},
		onLoad() {
			console.log(this.vuex_user.id)
			this.model.id = this.vuex_user.id
		}
	};
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}

	.u-form {
		background: #fff;
		padding: 0px 15px;
	}

	.remind-text {
		padding: 20rpx 30rpx;
		color: #666666;
	}
</style>
